<?php
namespace app\api\controller;
use think\Controller;
use app\common\lib;

class Upload extends Controller
{
    public function face_img()
    {
        $isLogin = lib\Tools::isLogin();
        if(!$isLogin) {
            return show('500','请登录后操作');
        }
        $file = request()->file('file');
        $dir = ROOT_PATH . 'public' . DS . 'face/';
        $info = $file->move($dir);
        if($info && $info->getPathname()) {
            try {
                Model('User')->save(['face'=>$info->getSaveName()],['id'=>$isLogin['id']]);
            }catch (\Exception $e) {
                return show('500',$e->getMessage());
            }
            return show('200','上传成功，刷新页面生效');
        }else {
            return show('500', '上传失败');
        }
        return show('500', '上传失败');
    }
}